package com.edu.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author:何包蛋
 * @Date :2022/12/10 - 12 - 10 - 16:14
 */
public class UserInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if(request.getSession().getAttribute("user") != null){
            return true;
        }else{
            System.out.println("被拦");
            response.sendRedirect("login.jsp");
            return false;
        }
    }
}
